package com.generator.demo.controller;

import com.generator.demo.service.TestService;
import com.generator.demo.model.vo.TestVo;
import com.generator.demo.model.dto.TestAddDto;
import com.generator.demo.model.dto.TestChangeDto;
import com.generator.demo.model.dto.TestListDto;
import com.generator.demo.model.dto.TestPageDto;
import com.generator.demo.model.dto.TestRemoveDto;
import com.generator.demo.service.TestService;
import java.util.List;
import javax.annotation.Resource;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.generator.demo.common.api.CommonResult;
import com.generator.demo.common.pageHelp.PageVo;

/**
 *  controller
 *
 * @author fxh
 * @since 2024-07-31
 */
@RestController
@RequestMapping(value = "/test")
@Api(tags = " TestController")
public class TestController {

    @Resource
    private TestService testService;

    @ApiOperation(value = "添加")
    @PostMapping("/add")
    public CommonResult<Boolean> add(TestAddDto testAddDto){
        testService.add( testAddDto);
        return CommonResult.success(true);
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("/remove")
    public CommonResult<Boolean> remove(TestRemoveDto testRemoveDto){
        testService.remove( testRemoveDto);
        return CommonResult.success(true);
    }

    @ApiOperation(value = "修改")
    @PutMapping("/change")
    public CommonResult<Boolean> change(TestChangeDto testChangeDto){
        testService.change( testChangeDto);
        return CommonResult.success(true);
    }

    @ApiOperation(value = "查询列表")
    @GetMapping("/list")
    public CommonResult<List<TestVo>> list(TestListDto testListDto){
        List<TestVo> testVoList = testService.list(testListDto);
        return CommonResult.success(testVoList);
    }

    @ApiOperation(value = "查询列表(分页)")
    @GetMapping("/page")
    public CommonResult<PageVo<TestVo>> page(TestPageDto test){
        PageVo<TestVo> testVoPage = testService.page(test);
        return CommonResult.success(testVoPage);
    }
}